package com.dhl.fin.api.controller;

import com.dhl.fin.api.common.controller.CommonController;
import com.dhl.fin.api.common.dto.ApiResponse;
import com.dhl.fin.api.common.exception.BusinessException;
import com.dhl.fin.api.domain.FamilyConfig;
import com.dhl.fin.api.service.FamilyConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author CuiJianbo
 * @since 2025/3/16
 */
@Slf4j
@RestController
@RequestMapping("familyconfig")
public class FamilyConfigController extends CommonController<FamilyConfig> {


    @Autowired
    private FamilyConfigService familyConfigService;

    @ResponseBody
    @RequestMapping("password")
    public ApiResponse setPassword(String password, String faUnicode, String oldPassword) throws Exception {
        familyConfigService.updateFamilyPassword(faUnicode, oldPassword, password);
        return ApiResponse.success();
    }

    @ResponseBody
    @RequestMapping("check/password")
    public ApiResponse checkPasswordIsRight(String password, String faUnicode) throws Exception {
        try {
            familyConfigService.checkPasswordRight(faUnicode, password);
        } catch (BusinessException e) {
            return ApiResponse.success("密码错误");
        }

        return ApiResponse.success();
    }

}


